<html>
<head>
<#import "/common/common.ftl" as netCommon>
<@netCommon.commonStyle />
<title></title>
<@netCommon.commonScript /> 
<@netCommon.commonLayui /> 
</head>
<body class="layui-layout-body show-scroll-y">
	<div class="layuimini-container">
		<div class="layui-row">
			<div class="layui-col-xs6">
				<div class="layui-upload-drag" id="upExcel">
				  <i class="layui-icon">&#xe67c;</i>
				  <p>点击上传，或将文件拖拽到此处</p>
				  <div id="upRes">
				    
				  </div>
				</div>
			</div>
			<div class="layui-col-xs6 layui-form layui-form-pane">
				<div class="layui-form-item layui-form-text">
				    <label class="layui-form-label">导入结果</label>
				    <div class="layui-input-block">
				      <textarea readonly="readonly" id="importRes" class="layui-textarea"></textarea>
				    </div>
				  </div>
			</div>
		</div>
		<div class="layui-row line-center">
			<button type="button" class="layui-btn"  id="downTemplate"><i class="layui-icon">&#xe601;</i>导入模板下载</button>
			<button type="button" class="layui-btn"  id="doImport"><i class="layui-icon">&#xe652;</i>开始导入</button>
		</div>
	</div>
	<script type="text/javascript">
	layui.use(["form","layer","upload"], function(){
		var upload = layui.upload;
		upload.render({
			elem: '#upExcel'
			,accept: "file"
			,acceptMime:"file/xls"
			,url: basePath+"/ryda/doImport"
			,auto: false //选择文件后不自动上传
			,bindAction:"#doImport"
			,choose: function(obj){
				//预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
				obj.preview(function(index, file, result){
					loadUploadFile(file);
				});
			},
			done:function(res, index, upload){
				layer.closeAll('loading');
				$("#importRes").val(res.msg);
				if(res.code == 2){
					if(res.data && res.data.length > 0){
						var _msg = $("#importRes").val();
						for(var i=0;i<res.data.length;i++){
							var iRes = res.data[i];
							if(iRes.flag == false){
								_msg += "\n"+iRes.msg;
							}
						}
						$("#importRes").val(_msg);
					}
				}
			},
			before:function(obj){
				layer.load();
			},
			error:function(index, upload){
				layer.closeAll('loading');
				$("#importRes").val("导入失败，服务异常！");
			}
		});
		function loadUploadFile(file){
			$("#upRes").empty();
			if(file){
				var sou = $("<span>"+file.name+"</span>");
				$("#upRes").append(sou);
			}
		}
		$("#downTemplate").click(function(){
			var opurl = basePath+"/static/imports/ryda_import.xls";
			window.open(opurl);
		});
	});
	</script>
</body>
</html>